package wiiusej.activeTaskManagement;

import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;

import wiiusej.Wiimote;

public class RumblerAtomicActuator implements Callable {

	
	private int freq;
	private Wiimote myWiimote;
	
	public RumblerAtomicActuator(Wiimote wiimote, int frequency){
		this.freq = freq;
		this.myWiimote = wiimote;
		
	}
	
	@Override
	public Object call() throws CancellationException{
		
		
		
		makeVibration();
		
		return null;
		/*
		try{
		
			while(true){
				makeVibration();	
			}
			
		
		}catch(CancellationException e){
		
			return null;
		}*/
		
		
		
		
	}
	
	
		
	private void makeVibration() {
		
		try {
			Thread.sleep(freq);
		} catch (InterruptedException e) {
			
		}catch (CancellationException e) {
			System.out.println("@@@ ACTIVATOR CANCELED");
			System.out.println("@@@ ACTIVATOR CANCELED");
			System.out.println("@@@ ACTIVATOR CANCELED");
			myWiimote.deactivateRumble();
			
		}
			
		myWiimote.activateRumble();
		
		try {
			Thread.sleep(50);
		} catch (InterruptedException e) {
			
		}catch (CancellationException e) {
			System.out.println("@@@ ACTIVATOR CANCELED");
			System.out.println("@@@ ACTIVATOR CANCELED");
			System.out.println("@@@ ACTIVATOR CANCELED");
			myWiimote.deactivateRumble();
			
		}
		
		myWiimote.deactivateRumble();
	}

	

}
